package com.cy.pj.ajax.controller;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/")
public class AjaxController {

    private List<String> list = new ArrayList<>();//假设这是存储名字的数据库

    @GetMapping("/doCheck")
    public String doCheck(String name){
        return list.contains(name)?name+"已存在":"123";
    }

    @PostMapping("/doSave")
    public String doSave(String name){
        list.add(name);
        return "save ok";
    }


    @CrossOrigin //跨域访问
    @GetMapping("doAjaxGet")
    public String daAjaxGet() throws InterruptedException {
        System.out.println("===doAjaxGet()===");
        Thread.sleep(5000);//模拟耗时操作
        return "Ajax Get Request Result";
    }
}
